package core

import (
	"crypto/md5"
	"encoding/hex"
	"strings"

	"github.com/go-basic/uuid"
)

// UUID 获取原生UUID
func UUID() string {
	return uuid.New()
}

// UUIDReplace 基于uuid进行替换操作方式的获取UUID
func UUIDReplace(old, new string) string {
	return strings.ReplaceAll(uuid.New(), old, new)
}

// MD5 基于内容生成MD5
func MD5(context string) string {
	m := md5.New()
	m.Write([]byte(context))
	return hex.EncodeToString(m.Sum(nil))
}

// GeneratorSqlSet 生成set sql
func GeneratorSqlSet(params map[string]interface{}) (string, []interface{}) {
	result := ""
	resultParam := make([]interface{}, 0)
	for key := range params {
		result = result + " " + key + " = ?,"
		resultParam = append(resultParam, params[key])
	}
	return "set " + result[:len(result)-1], resultParam
}
